//
// Created by Administrator on 2022/8/25.
//

#ifndef TPSERVER_TP_ATOMIC_H
#define TPSERVER_TP_ATOMIC_H
#include <sys/types.h>

typedef volatile int   tp_atomic_t;

#define ngx_memory_barrier()

// 比較並替換函數
static inline int tp_atomic_cmp_set(tp_atomic_t *lock, int old, int set)
{
    if((*lock) != old)
        return 0;
    else
        *lock = set;
    return 1;
}
#define tp_trylock(lock) ((*lock) == 0 && tp_atomic_cmp_set(lock, 0 , 1))
#define tp_unlock(lock) (*lock) = 0
#endif //TPSERVER_TP_ATOMIC_H
